package com.ruoyi.web.controller.video;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.video.VsDramasCategory;
import com.ruoyi.system.service.video.IVsDramasCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 商城分类Controller
 * 
 * @author ruoyi
 * @date 2024-04-19
 */
@Api(tags = "商城分类")
@RestController
@RequestMapping("/video/category")
public class VsDramasCategoryController extends BaseController
{
    @Autowired
    private IVsDramasCategoryService vsDramasCategoryService;

    /**
     * 查询商城分类列表
     */
//    @ApiOperation("查询父级分类")
    @GetMapping("/fatherList")
    public TableDataInfo fatherList(VsDramasCategory vsDramasCategory)
    {
        List<VsDramasCategory> list = vsDramasCategoryService.selectFatherCategoryList(vsDramasCategory);
        return getDataTable(list);
    }

    /**
     * 查询商城分类列表
     */
    @ApiOperation("查询父级分类下的子级分类信息")
    @GetMapping("/childrenList")
    public TableDataInfo childrenList(VsDramasCategory vsDramasCategory, HttpServletRequest request)
    {
        if (!StringUtils.isEmpty(request.getHeader("Lang-Id"))) {
            Long integer = Long.valueOf(request.getHeader("Lang-Id"));
            vsDramasCategory.setLangId(integer);
        }
        List<VsDramasCategory> list = vsDramasCategoryService.selectChildrenCategoryList(vsDramasCategory);
        return getDataTable(list);
    }

    /**
     * 导出商城分类列表
     */
//    @Log(title = "商城分类", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, VsDramasCategory vsDramasCategory)
//    {
//        List<VsDramasCategory> list = vsDramasCategoryService.selectVsDramasCategoryList(vsDramasCategory);
//        ExcelUtil<VsDramasCategory> util = new ExcelUtil<VsDramasCategory>(VsDramasCategory.class);
//        util.exportExcel(response, list, "商城分类数据");
//    }

    /**
     * 获取商城分类详细信息
     */
//    @ApiOperation("根据id获取分类详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vsDramasCategoryService.selectVsDramasCategoryById(id));
    }

    /**
     * 新增商城分类
     */
//    @ApiOperation("新增商城分类")
    @Log(title = "商城分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasCategory vsDramasCategory)
    {
        return toAjax(vsDramasCategoryService.insertVsDramasCategory(vsDramasCategory));
    }

    /**
     * 修改商城分类
     */
//    @ApiOperation("修改商城分类")
    @Log(title = "商城分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasCategory vsDramasCategory)
    {
        return toAjax(vsDramasCategoryService.updateVsDramasCategory(vsDramasCategory));
    }

    /**
     * 删除商城分类
     */
//    @ApiOperation("删除商城分类")
    @Log(title = "商城分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vsDramasCategoryService.deleteVsDramasCategoryByIds(ids));
    }

    /**
     * 修改商城分类
     */
//    @ApiOperation("修改商城分类")
    @Log(title = "商城分类", businessType = BusinessType.UPDATE)
    @PostMapping("/batchUpdate")
    public AjaxResult batchUpdateVsDramasCategory(@RequestBody List<VsDramasCategory> vsDramasCategory)
    {
        return toAjax(vsDramasCategoryService.batchUpdateVsDramasCategory(vsDramasCategory));
    }

    /**
     * 查询短剧列表
     */
    @ApiOperation("查询对应分类下的短剧列表")
    @PostMapping("/categoryList")
    public TableDataInfo categoryList(@RequestBody VsDramasCategory category, HttpServletRequest request)
    {
        startPage();
        if (request.getHeader("Lang-Id") != null) {
            category.setLangId(Long.valueOf(request.getHeader("Lang-Id")));
        }
        List<VsDramasCategory> list = vsDramasCategoryService.selectHomeVideos(category);
        return getDataTable(list);
    }

}
